import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
/*导入自定义的主题文件*/
import "./assets/theme/index.css"
//引入字体文件
import './assets/font/iconfont.css'
import axios from 'axios'
import * as echarts from 'echarts';
import '../public/static/theme/chalk.js'
import '../public/static/theme/vintage.js'
import socket_service from "./utils/socket_service";

//对服务器进行websocket的连接
socket_service.Instance.connect();

Vue.prototype.$socket = socket_service.Instance;
Vue.prototype.axios = axios;
Vue.prototype.echarts = echarts;

Vue.use(ElementUI);

/*项目部署：使用项目名称    /api  */
axios.defaults.baseURL = '/api';
axios.defaults.withCredentials = true;

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
    if (to.name == 'LoginPage') {//如果是登录页，直接登录
      next();
      return;
    }
    if (store.state.userInfo!=null) { // 判断本地是否存在access_token
      next()
    } else {
      // 未登录,跳转到登陆页面，并且带上 将要去的地址，方便登陆后跳转。
      next({
            path: '/login',
            query:{ referrer: to.fullPath}
        })
    }
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
